<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>课程-助教</title>

<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/course-index.css'/>" />
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
</head>
<body>
	<div class="container-fluid main">
		<div class="row">
			<div class="col-md-12">
				<%@include file="/common/header.jsp"%>
			</div>
			<div class="col-md-12">
				<%@include file="common/courseHeader.jsp"%>
			</div>
			<div class="col-md-12">
				<div class="row">
					<div class="col-md-3">
						<%@include file="common/courseLeft.jsp"%>
					</div>
					<div class="col-md-9">
						<div class="row">
							<div class="col-md-12">
								<%@include file="common/courseNavbar.jsp"%>
							</div>
							<div class="col-md-12">
								<div class="assistant">
									<div class="row">
										<div class="col-md-12" style="text-align:center;">
											<h3>助教列表</h3>
										</div>
										<div class="col-md-12">
											<button class="btn btn-primary" style="float:right;box-shadow: 3px 3px 3px #80b3e0;" id="assistantDelete">删除</button>
											<button type="button" class="btn btn-primary" style="float:right;margin-right:2rem;box-shadow: 3px 3px 3px #80b3e0;" id="addassi">添加助教</button>
										</div>
										<!--已存在助教列表-->
										<div class="col-md-12">
											<table class="table table-hover">
												<thead>
													<tr>
														<th>序号</th>
														<th>学号</th>
														<th>姓名</th>
														<th id="check-text"><input type="checkbox" name="" id="all-check" value="" />全选</th>
													</tr>
												</thead>
												<tbody id="appendAssistantList">
													
												</tbody>
											</table>
										</div>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<%@include file="/common/footer.jsp"%>
	<div id="addassistant" style="display:none;font-size:1.6rem;">
		<%@include file="courseAddAssistant.jsp"%>
	</div>
	
</body>
<script>
var data=${data};
$(document).ready(function() {
	if (data.status != "success") {
		layer.alert(data.message);
		return;
	}
	$("#assistant").css("color","#00b43c");
	initAssistantList(data.data);
})
$(function(){
	changeUrl(data.data.course.id);
	fetchCourse(data.data.course.id);
	$("#assistantDelete").click(assistantDelete);
	
	$("#all-check").click(function(){
		//全选状态
		if($("#all-check").is(':checked')){
			$('input[name="deleteAssistantId"]').each(function(){
				$(this).prop("checked", true);
			});
		}else{//全不选状态
			$('input[name="deleteAssistantId"]').each(function(){
				$(this).prop("checked", false);
			});
		}
	});
	
	$("#addassi").click(function(){
		layer.open({
			type: 1,
			title: '添加助教',
			fixed: false, //不固定
			maxmin: true,
			closeBtn: 1,
			skin: 'layui-layer-molv',
			area: ['80rem', '40rem'],
			content: $("#addassistant"),
			end: function() {
				window.location.reload();
            }
		});
	});
});

var initAssistantList = function(data){
	var appendAssistantList =$("#appendAssistantList");
	appendAssistantList.empty();
	var seacherData =$("#seacherData");
	seacherData.empty();
	var s="";
	var assistants=data.Assistants;
	if(assistants.length <= 0){
		s += "<tr><td colspan=\"4\">还没有助教</td></tr>";
	}else{
		for(var i=0;i<assistants.length;i++){
			var item=assistants[i];
			s+="<tr>";
			s+="<th scope=\"row\">"+(i+1)+"</th>";
			s+="<td title=\""+item.assistantCode+"\">"+item.assistantCode+"</td>";
			s+="<td title=\""+item.name+"\">"+item.name+"</td>";
			s+="<td><input type=\"checkbox\" name=\"deleteAssistantId\" value=\""+item.id+"\" /></td>";
			s+="</tr>";
		}
	}
	
	appendAssistantList.append(s);
}
var assistantDelete = function(){
	var courseCourseId = data.data.course.id;
	var assistantIds =[];
	$('input[name="deleteAssistantId"]:checked').each(function(){ 
		assistantIds.push($(this).val()); 
	});
	if(assistantIds.length<=0){
		layer.alert("请选择待删除助教");
		return ;
	}
	var json={
			ids:assistantIds,
			keyId:courseCourseId
	};
	$.post(CONTEXT_PATH+"accontrol/batchDelete", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			window.location.reload();
		}else{
			layer.alert(data.message);
		}
	});
}

</script>
</html>